
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import s_put from '@dfeidao/atom-web/storage/put';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';
// import { send_msg as url } from './config';
import P03 from './P03';
import P04 from './P04';
import P05 from './P05';

export default async function a000(fd: IFeidaoAiBrowserComponent) {
	const prid = fd.data.node.querySelector<HTMLSpanElement>('[data-feidao-id="user"]').getAttribute('prid');
	// const user = await whoami(get_user_info);
	// console.log(user);
	await s_put('productid', prid);

	set(fd, 'page_no', 1);
	set(fd, 'page_size', 20);
	set(fd, 'productid', prid);
	const page_no = 1;
	const page_size = 20;
	const query = { productid: prid, page_no, page_size };
	// console.log(query);
	show_loading();
	const res = await nodejs<{ dataArray: object[], count: number, page_no: number, page_size: number }>('roler/zj-000001/s001', query);
	hide_loading();
	if (res.dataArray.length === 0) {
		render(fd, '', P03, 'P03', 'inner');
		render(fd, '', P04, 'P04', 'inner');
		fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="P05"]').innerHTML = '';
	} else {
		render(fd, res.dataArray, P03, 'P03', 'inner');
		res.page_no = page_no;
		fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="P04"]').innerHTML = '';
		res.page_size = page_size;
		if (res.count >= 20) {
			render(fd, res, P05, 'P05', 'inner');
		}
	}
}
